import { ArchiveUsers } from './archiveUser';
let _ArchiveUsers = ArchiveUsers;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import ArchiveUserMock from './mdp/arc/archiveUserMock';
 * ArchiveUserMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/archiveUser/listKey').reply(config => {
      let params = config.params;
      let mockArchiveUsers = _ArchiveUsers.filter(archiveUser => {
      	if(params.id||params.id==''){ if( archiveUser.id.indexOf(params.id)>=0) return true;}
      	if(params.archiveId||params.archiveId==''){ if( archiveUser.archiveId.indexOf(params.archiveId)>=0) return true;}
      	if(params.userid||params.userid==''){ if( archiveUser.userid.indexOf(params.userid)>=0) return true;}
      	if(params.canRead||params.canRead==''){ if( archiveUser.canRead.indexOf(params.canRead)>=0) return true;}
      	if(params.canEdit||params.canEdit==''){ if( archiveUser.canEdit.indexOf(params.canEdit)>=0) return true;}
      	if(params.canDown||params.canDown==''){ if( archiveUser.canDown.indexOf(params.canDown)>=0) return true;}
      	if(params.canDel||params.canDel==''){ if( archiveUser.canDel.indexOf(params.canDel)>=0) return true;}
      	if(params.remark||params.remark==''){ if( archiveUser.remark.indexOf(params.remark)>=0) return true;}
      	if(params.isGet||params.isGet==''){ if( archiveUser.isGet.indexOf(params.isGet)>=0) return true;}
      	if(params.needReply||params.needReply==''){ if( archiveUser.needReply.indexOf(params.needReply)>=0) return true;}
      	if(params.replyTime||params.replyTime==''){ if( archiveUser.replyTime.indexOf(params.replyTime)>=0) return true;}
      	if(params.encryptType||params.encryptType==''){ if( archiveUser.encryptType.indexOf(params.encryptType)>=0) return true;}
      	if(params.endDate||params.endDate==''){ if( archiveUser.endDate.indexOf(params.endDate)>=0) return true;}
      	if(params.isSendEmail||params.isSendEmail==''){ if( archiveUser.isSendEmail.indexOf(params.isSendEmail)>=0) return true;}
      	if(params.isSendWeixin||params.isSendWeixin==''){ if( archiveUser.isSendWeixin.indexOf(params.isSendWeixin)>=0) return true;}
      	if(params.isSendOa||params.isSendOa==''){ if( archiveUser.isSendOa.indexOf(params.isSendOa)>=0) return true;}
      	if(params.isSendShortMsg||params.isSendShortMsg==''){ if( archiveUser.isSendShortMsg.indexOf(params.isSendShortMsg)>=0) return true;}
      	if(params.createDate||params.createDate==''){ if( archiveUser.createDate.indexOf(params.createDate)>=0) return true;}
      	if(params.sendDate||params.sendDate==''){ if( archiveUser.sendDate.indexOf(params.sendDate)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockArchiveUsers
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/archiveUser/list').reply(config => {
      let params = config.params;
      let mockArchiveUsers = _ArchiveUsers.filter(archiveUser => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(archiveUser.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.archiveId||params.archiveId==''){if(archiveUser.archiveId.indexOf(params.archiveId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userid||params.userid==''){if(archiveUser.userid.indexOf(params.userid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canRead||params.canRead==''){if(archiveUser.canRead.indexOf(params.canRead)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canEdit||params.canEdit==''){if(archiveUser.canEdit.indexOf(params.canEdit)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canDown||params.canDown==''){if(archiveUser.canDown.indexOf(params.canDown)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canDel||params.canDel==''){if(archiveUser.canDel.indexOf(params.canDel)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(archiveUser.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isGet||params.isGet==''){if(archiveUser.isGet.indexOf(params.isGet)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.needReply||params.needReply==''){if(archiveUser.needReply.indexOf(params.needReply)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.replyTime||params.replyTime==''){if(archiveUser.replyTime.indexOf(params.replyTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.encryptType||params.encryptType==''){if(archiveUser.encryptType.indexOf(params.encryptType)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.endDate||params.endDate==''){if(archiveUser.endDate.indexOf(params.endDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendEmail||params.isSendEmail==''){if(archiveUser.isSendEmail.indexOf(params.isSendEmail)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendWeixin||params.isSendWeixin==''){if(archiveUser.isSendWeixin.indexOf(params.isSendWeixin)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendOa||params.isSendOa==''){if(archiveUser.isSendOa.indexOf(params.isSendOa)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendShortMsg||params.isSendShortMsg==''){if(archiveUser.isSendShortMsg.indexOf(params.isSendShortMsg)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDate||params.createDate==''){if(archiveUser.createDate.indexOf(params.createDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendDate||params.sendDate==''){if(archiveUser.sendDate.indexOf(params.sendDate)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockArchiveUsers
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockArchiveUsers.length;
      mockArchiveUsers = mockArchiveUsers.filter((archiveUser, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockArchiveUsers,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/archiveUser/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _ArchiveUsers = _ArchiveUsers.filter(archiveUser => archiveUser.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/archiveUser/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _ArchiveUsers = _ArchiveUsers.filter(archiveUser => !params.includes(archiveUser.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/archiveUser/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,userid,canRead,canEdit,canDown,canDel,remark,isGet,needReply,replyTime,encryptType,endDate,isSendEmail,isSendWeixin,isSendOa,isSendShortMsg,createDate,sendDate } = params;
      _ArchiveUsers.some(archiveUser => {
        if (archiveUser.id === id) {
			archiveUser.id = id;
			archiveUser.archiveId = archiveId;
			archiveUser.userid = userid;
			archiveUser.canRead = canRead;
			archiveUser.canEdit = canEdit;
			archiveUser.canDown = canDown;
			archiveUser.canDel = canDel;
			archiveUser.remark = remark;
			archiveUser.isGet = isGet;
			archiveUser.needReply = needReply;
			archiveUser.replyTime = replyTime;
			archiveUser.encryptType = encryptType;
			archiveUser.endDate = endDate;
			archiveUser.isSendEmail = isSendEmail;
			archiveUser.isSendWeixin = isSendWeixin;
			archiveUser.isSendOa = isSendOa;
			archiveUser.isSendShortMsg = isSendShortMsg;
			archiveUser.createDate = createDate;
			archiveUser.sendDate = sendDate
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/archiveUser/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,userid,canRead,canEdit,canDown,canDel,remark,isGet,needReply,replyTime,encryptType,endDate,isSendEmail,isSendWeixin,isSendOa,isSendShortMsg,createDate,sendDate } = params;
      _ArchiveUsers.push({
		id:id,
		archiveId:archiveId,
		userid:userid,
		canRead:canRead,
		canEdit:canEdit,
		canDown:canDown,
		canDel:canDel,
		remark:remark,
		isGet:isGet,
		needReply:needReply,
		replyTime:replyTime,
		encryptType:encryptType,
		endDate:endDate,
		isSendEmail:isSendEmail,
		isSendWeixin:isSendWeixin,
		isSendOa:isSendOa,
		isSendShortMsg:isSendShortMsg,
		createDate:createDate,
		sendDate:sendDate
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};